﻿using Avalonia.Controls.ApplicationLifetimes;
using MsBox.Avalonia.Enums;
using MsBox.Avalonia;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tmds.DBus.Protocol;
using Avalonia.Controls.Notifications;
using Avalonia.Controls;

namespace DX
{
    class DefaultMessageCenter : IMessageCenter
    {

        public DefaultMessageCenter(IClassicDesktopStyleApplicationLifetime applicationLifetime)
        {
            this.applicationLifetime = applicationLifetime;
        }
        private readonly IClassicDesktopStyleApplicationLifetime applicationLifetime;
        public Task<bool> Confirmation(string message)
        {

            return Confirmation("确认", message);
        }

        public   async Task<bool> Confirmation(string title, string message)
        {
            var box = MessageBoxManager.GetMessageBoxStandard(title, message, ButtonEnum.OkCancel);
        
            var result = await   box.ShowAsync( ) ;
            return  result == ButtonResult.Ok ;
        }

        public Task Notification(string message)
        {
            var topLevel = TopLevel.GetTopLevel(applicationLifetime.Windows.Last(n=>n.IsActive));
            var notificationManager = new WindowNotificationManager(topLevel)
            {
                Position = NotificationPosition.BottomRight
            };
            notificationManager.Show(new Notification { Message = message,  });
            return Task.CompletedTask;
        }

        public Task Show(string message)
        {
            return Show("消息", message);
        }

        public async Task Show(string title, string message)
        {

            var box = MessageBoxManager.GetMessageBoxStandard(title, message);
            await box.ShowAsync();
        }

        public Task<OptionItem> ShowOptions(string title, string message, OptionItem[] options)
        {
            throw new NotImplementedException();
        }

        public async Task<OptionItem> ShowOptions(string message, OptionItem[] options)
        {
            return await ShowOptions("", message, options);
        }
    }
}
